package algorithm.dynamicProgramming.leetcode;
//1567. 乘积为正数的最长子数组长度
public class GetMaxLen {
    public static void main(String[] args) {
        int[] data = {1,-2,-3,4};
        System.out.println(getMaxLen(data));

    }


    //贪心
    public static int getMaxLen(int[] nums) {
        int res = 0;
        int z = 0,f = 0;
        for (int n:nums) {
            if(n == 0){
                z = 0;  // 正数长度
                f = 0;  // 负数长度
            }else if(n > 0){
                z++;
                if(f > 0) f++;
                res = Math.max(res,z);
            }else {
                int temp = z;
                z = f;
                f =temp;
                f++;
                if(z>0) z++;
                res = Math.max(res,z);
            }
        }
        return res;
    }
}
